package com.operator.Activitys.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.operator.Activitys.R;
import com.operator.Activitys.adapter.base.BaseRecyclerViewAdapter;
import com.operator.Activitys.bean.StockQuery;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：金泽云 手机app
 * 类描述：库存查询 适配器
 * 创建人：张飞祥
 * 创建时间：2018/5/21 13:21
 * 修改人：张飞祥
 * 修改时间：2018/5/21 13:21
 * 修改备注：
 */
public class StockQueryAdapter extends BaseRecyclerViewAdapter {


    //上下文
    private Context mContext;
    //数据集合
    private List<StockQuery> mList;

    public StockQueryAdapter(Context mContext, List<StockQuery> mList) {
        super(mContext, mList);
        this.mContext = mContext;
        this.mList = mList;
    }


    @Override
    protected int getLayoutItemResId() {
        return R.layout.item_stock_query;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        if (viewHolder instanceof StockQueryViewHolder) {

            //TODO 库存查询 viewHolder
            final StockQueryViewHolder holder = (StockQueryViewHolder) viewHolder;
            //TODO  将数据保存在itemView的Tag中，以便点击时进行获取
            holder.itemView.setTag(position);
            //TODO  获取数据源 第 i 个 实体数据
            StockQuery stockQuery = mList.get(position);

            /**
             * 设置数据源
             */
            //iccid
            holder.tvItemStockIccid.setText(stockQuery.getICCID());
            //运营商
            holder.tvItemStockOperator.setText(stockQuery.getCarrieroperator());
            //最晚激活日期
            holder.tvItemStockDate.setText(stockQuery.getLateActivationTime());

        }
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new StockQueryViewHolder(view);
    }


    /**
     * ViewHolder
     */
    public class StockQueryViewHolder extends RecyclerView.ViewHolder {

        //ICCID
        @Bind(R.id.tv_item_stock_iccid)
        TextView tvItemStockIccid;
        //运营商
        @Bind(R.id.tv_item_stock_operator)
        TextView tvItemStockOperator;
        //最晚激活日期
        @Bind(R.id.tv_item_stock_date)
        TextView tvItemStockDate;

        public StockQueryViewHolder(View itemView) {
            super(itemView);
            //绑定控件
            ButterKnife.bind(this, itemView);
            //屏幕适配
            AutoUtils.autoSize(itemView);
        }
    }
}
